package yhao.demo.service.erp.workflow.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import yhao.demo.service.erp.workflow.apilist.form.flow.*;
import yhao.infra.apilist.RequestResult;
import yhao.infra.apilist.RestfulBaseController;
import yhao.infra.apilist.validate.IdForm;
import yhao.infra.common.model.Pagination;
import yhao.demo.service.erp.workflow.apilist.model.flow.FlowNodeTemplateModel;
import yhao.demo.service.erp.workflow.apilist.model.flow.FlowNodeWarnTemplateModel;
import yhao.demo.service.erp.workflow.apilist.model.flow.FlowProcessDefinitionModel;
import yhao.demo.service.erp.workflow.service.ProcessService;

import java.util.List;

/**
 * 流程管理Api
 */
@RestController
@RequestMapping(value = "/process")
public class ProcessApi extends RestfulBaseController {
    @Autowired
    private ProcessService processService;

    @PostMapping("/saveNodeTemplate")
    public RequestResult<FlowNodeTemplateForm> saveNodeTemplate(@RequestBody FlowNodeTemplateForm form){
        return new RequestResult(processService.saveNodeTemplate(form));
    }

    @PostMapping("/queryNodeTemplate")
    public RequestResult<List<FlowNodeTemplateModel>> queryNodeTemplate(){
        return new RequestResult(processService.queryNodeTemplate());
    }

    @PostMapping("/queryNodeWarnTemplateByNodeTemplateId")
    public RequestResult<FlowNodeWarnTemplateModel> queryNodeWarnTemplateByNodeTemplateId(@RequestBody IdForm form){
        return new RequestResult(processService.queryNodeWarnTemplateByNodeTemplateId(form));
    }

    @PostMapping("/saveProcessDefinition")
    public RequestResult<Boolean> saveProcessDefinition(@RequestBody FlowProcessDefinitionForm form){
        return new RequestResult(processService.saveProcessDefinition(form));
    }

    @PostMapping("/updateBizCode")
    public RequestResult<FlowProcessBizCodeChangeForm> updateBizCode(@RequestBody FlowProcessBizCodeChangeForm form){
        return new RequestResult(processService.updateBizCode(form));
    }

    @PostMapping("/saveNodeItemTemplate")
    public RequestResult<FlowNodeItemTemplateForm> saveNodeItemTemplate(@RequestBody FlowNodeItemTemplateForm form){
        return new RequestResult(processService.saveNodeItemTemplate(form));
    }

    @PostMapping("/queryProcessDefinition")
    public RequestResult<Pagination<FlowProcessDefinitionModel>> queryProcessDefinition(@RequestBody FlowProcessQueryForm form){
        return new RequestResult(processService.queryProcessDefinition(form));
    }
}
